package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTodoevent;
import com.ruoyi.system.service.ISysTodoeventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代办事项Controller
 *
 * @author ruoyi
 * @date 2022-01-10
 */
@Api(tags = "待办事项")
@RestController
@RequestMapping("/system/todoevent")
public class SysTodoeventController extends BaseController
{
    @Autowired
    private ISysTodoeventService sysTodoeventService;

    /**
     * 查询代办事项列表
     */
    @ApiOperation(value = "查询代办事项列表")
    @PreAuthorize("@ss.hasPermi('system:todoevent:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTodoevent sysTodoevent)
    {
        startPage();
        List<SysTodoevent> list = sysTodoeventService.selectSysTodoeventList(sysTodoevent);
        return getDataTable(list);
    }

    /**
     * 根据id获取详细信息
     */
    @ApiOperation(value = "根据id获取详细信息")
    @PreAuthorize("@ss.hasPermi('system:todoevent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysTodoeventService.selectSysTodoeventById(id));
    }

    /**
     * 根据处理人id获取代办列表
     */
    @ApiOperation(value = "根据处理人id获取代办列表")
    @PreAuthorize("@ss.hasPermi('system:todoevent:query')")
    @GetMapping(value = "/{dealId}")
    public AjaxResult getcurrentInfo(@PathVariable("dealId") Long handleId)
    {
        return AjaxResult.success(sysTodoeventService.selectSysTodoeventByHandleid(handleId));
    }

    /**
     * 根据处理人id获取代办个数
     */
    @ApiOperation(value = "根据处理人id获取代办个数")
    @PreAuthorize("@ss.hasPermi('system:todoevent:queryCount')")
    @GetMapping(value = "/queryCount/{dealId}")
    public AjaxResult getCountByHandleId(@PathVariable("dealId") Long handleId)
    {
        return AjaxResult.success(sysTodoeventService.getCountByHandleId(handleId));
    }

    /**
     * 新增待办事项
     */
    @ApiOperation(value = "新增待办事项")
    @PreAuthorize("@ss.hasPermi('system:todoevent:add')")
    @Log(title = "新增代办事项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTodoevent sysTodoevent)
    {
        return toAjax(sysTodoeventService.insertSysTodoevent(sysTodoevent).intValue());
    }

    /**
     * 修改代办事项
     */
    @ApiOperation(value = "修改代办事项")
    @PreAuthorize("@ss.hasPermi('system:todoevent:edit')")
    @Log(title = "修改代办事项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTodoevent sysTodoevent)
    {
        return toAjax(sysTodoeventService.updateSysTodoevent(sysTodoevent));
    }

    /**
     * 删除代办事项
     */
    @ApiOperation(value = "删除代办事项")
    @PreAuthorize("@ss.hasPermi('system:todoevent:remove')")
    @Log(title = "删除代办事项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysTodoeventService.deleteSysTodoeventByIds(ids));
    }
}
